#include "data_global.h"
#include "pwmdriver.h"

extern pthread_mutex_t mutex_buzzer;
extern pthread_cond_t cond_buzzer;
extern struct makeru_ctrl_data ctrl_data[MONITOR_NUM];

void *pthread_buzzer(void *arg)
{
    int fd = -1;
    printf("pthread_buzzer\n");

    if((fd = open(BEEPER_DEV, O_RDWR | O_NONBLOCK)) == -1)
    {
        perror("beeper open");
        exit(-1);
    }

    while(1)
    {
		pthread_mutex_lock(&mutex_buzzer);
		pthread_cond_wait(&cond_buzzer, &mutex_buzzer);
        if(ctrl_data[HOME_ID].beeperstate) ioctl(fd, BEEP_ON);
        else ioctl(fd, BEEP_OFF);
		pthread_mutex_unlock(&mutex_buzzer);
    }
#if 0
    open(dev_buzzer) 打开设备
    pthread_cond_wait(cond_buzzer) 等待条件锁
    获取dev_buzzer_mask(控制标志)
    通过ioctl()控制buzzer
#endif
}